<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">  
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semantic/dist/semantic.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
    <title>服务设置</title>  
</head>
<body>

<div class="ui segment" id="n-page">
        <div class="ui segment" id="n-content" >
            <form class="ui form">
                <div class="field">
                    <label>服务项目名称</label>
                    <div class="ui input">
                        <input type="text" name="name" id="name" value="${desc.name}" placeholder="请输入服务项目名称">
                    </div>
                </div>
                <div class="field">
                    <label>服务项目金额</label>
                    <div class="ui input">
                        <input type="text" name="spec" id="spec" value="${desc.spec}" placeholder="请输入服务项目金额">
                    </div>
                </div>
                <div class="field">
                    <label>服务项目单位</label>
                    <div class="ui input">
                        <input type="text" name="unit" id="unit" value="${desc.unit}" placeholder="请输入服务项目单位(如：次45分钟或份)">
                    </div>
                </div>
                <div class="field">
                    <label>服务项目标签</label>
                    <div class="ui input">
                        <input type="text" name="tag" id="tag" value="${desc.tag}" placeholder="请输入服务项目标签">
                    </div>
                </div>
	            <div class="field">
                    <label>服务项目描述</label>
                    <div class="ui input">
                        <textarea rows="5" cols="5" name="remark" id="remark" val placeholder="请输入服务项目描述">${desc.remark}</textarea>
                    </div>
                </div>
                <input type="hidden" name="descid" id="descid" value="${desc.id}"/>
            </form> 
        </div>

        <div class="ui segment" id="cont-next" style="padding-top:0px;">
            <div class="fluid ui button" id="next">提交修改</div>
        </div>

</div>

<script src="${ctx}/resources/jweixin-1.0.0.js"></script>
<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semantic/dist/semantic.min.js" type="text/javascript"></script>
<script type="text/javascript">

    var handler = { 
        activate: function() { 
            if($(this).attr('id') == 'next') {
                var name  = $("#name").val();
                var spec  = $("#spec").val();
                var unit  = $("#unit").val();
                var tag = $("#tag").val()
                var remark= $("#remark").val();
                var descid= $("#descid").val();
                if(!name || name=="") {
                    alert("您必须输入服务项目名称");
                    return false;
                }
                if(!spec || spec =="") {
                    alert("您必须输入服务项目金额");
                    return false;
                }
                if(!/^[0-9]+$/.test(spec) || spec < 0 || spec > 50000) {
                    alert("您必须输入合格的服务项目金额(数字)"); 
                    return false;
                }
                if(!unit || unit =="") {
                    alert("您必须服务项目单位（如：份或次90分钟）");
                    return false;
                }
                if(!tag || tag =="") {
                    alert("您必须服务项目标签类（如：份或次90分钟）");
                    return false;
                }
                if(remark.length > 1000) {
                    alert("服务项目描述太长，已超过1000字");
                    return false;
                }
                if(!remark || remark == "") {
                    alert("您必须输入服务项目描述");
                    return false;
                }
                var param = {};
                var postUrl = '${ctx}/wechat/hunter/createDesc.do';
                if (descid && descid >"0") {
                	 postUrl = '${ctx}/wechat/hunter/updateDesc.do';
                     param['id']  = descid;
                }
                else
                {
                	 postUrl = '${ctx}/wechat/hunter/createDesc.do';
                }
                param['name'] = name;
                param['spec']   = spec;
                param['unit'] = unit;
                param['tag'] = tag;
                param['remark']   = remark;
                console.log(param);
                $(this).addClass('disabled');
                var that = this;
                $.ajax({ 
                    url: postUrl, 
                    type: "POST", 
                    data: param,
                    success: function(data, status){
                        if (data.errorcode == 0){
                            //var job = data.data;
                            var forwardUrl = '${ctx}/wechat/hunter/descList.page';
                            window.location.href = forwardUrl;
                        }else{
                            alert(data.msg);
                            $(that).removeClass('disabled');
                        }
                    }, 
                    error: function(){ 
                        alert("服务出错，请稍后尝试"); 
                        $(that).removeClass('disabled');
                    } 
                });
            }
        } 
    };


    $(document).ready(function() { 
      
        $('.button').on('click', handler.activate);
           
      /*   wx.ready(function() {
            wx.hideOptionMenu();
        }); */
    });

</script>
</body>
</html>